/*
function init() {
    map = new OpenLayers.Map("map");
    
    sel = new OpenLayers.Layer.WMS(
              "Selected",
              "http://gis-lab.info/cgi-bin/mapserv?",
              {map:"/usr/local/www/gis-lab/data/programs/mapserver/ol-search/layer.map",layers: 'selected',sql:"select * from settlements where name='-1'",transparent:"true"},{singleTile:true});

    geosample = new OpenLayers.Layer.WMS(
              "Selected",
              "http://gis-lab.info:8180/geoserver/wms",
              {layers:"geosample:ecoregions,geosample:road-l-osm,geosample:settlements",transparent:"false"});
    
    map.addLayers([geosample,sel]);
    var bounds = new OpenLayers.Bounds.fromString('82,54,84,56');
    map.zoomToExtent(bounds);

}
*/

function init_AJAX() {
try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript
alert("XMLHttpRequest not supported");
return null;
};


function findparcel() {
//_map = document.getElementById("OpenLayers.Map");
//_map = this.OpenLayers.Map;
Proj4js.defs["EPSG:4284"] = '+proj=longlat+ellps=kras+towgs84=23.92,-141.27,-80.9,-0,0.35,0.82,-0.12+no_defs';
Proj4js.defs["EPSG:4326"] = '+proj=longlat+ellps=WGS84+datum=WGS84+no_defs+towgs84=0,0,0';
Proj4js.defs["EPSG:900913"] = '+proj=merc+a=6378137+b=6378137+lat_ts=0.0+lon_0=0.0+x_0=0.0+y_0=0+k=1.0+units=m+nadgrids=@null+wktext+over+no_defs';

var src = new Proj4js.Proj("EPSG:4284");
var dst = new Proj4js.Proj("EPSG:900913");

var req = init_AJAX();
req.open("GET", "http://212.26.144.107:8092/php/findparcel.php?name="+(document.getElementById("searchp").value));
req.onreadystatechange = function () {
if (req.readyState==4) {
	if (req.status==200) {
		var response = req.responseText;
		var split_response = response.split(",");

		//alert (response);
		var bounds_res = new OpenLayers.Bounds.fromString(response);

		//alert (bounds_res);

                x1=split_response[0];
                y1=split_response[1];
		x2=split_response[2];
                y2=split_response[3];

		
		//alert ("EPSG:4284 " + x + "," +y);

		var point1 = new Proj4js.Point(x1,y1);
		var point2 = new Proj4js.Point(x2,y2);

		Proj4js.transform(src, dst, point1);
		Proj4js.transform(src, dst, point2);

		var new_response =  point1.x + "," + point1.y + "," + point2.x + "," + point2.y;
		var new_bounds_res = new OpenLayers.Bounds.fromString(new_response);
		
		//alert ("EPSG:900913 " + point.x + "," + point.y);

		
		//var bounds_res_4326 = bounds_res.transform(new OpenLayers.Projection("EPSG:4284"), new OpenLayers.Projection("EPSG:4326"));
               
                //alert(bounds_res_4326); 

		//var bounds_res_900913 = bounds_res_4326.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
		//var bounds_res_900913 = bounds_res.transform(new OpenLayers.Projection("EPSG:4284"), new OpenLayers.Projection("EPSG:900913"));
		
		//alert (bounds_res_900913);
		//map.zoomToExtent(bounds_res_900913);
		
		map.zoomToExtent(new_bounds_res);

		x=new_bounds_res.centerLonLat.lat;
		y=new_bounds_res.centerLonLat.lon;

		map.setCenter(new OpenLayers.LonLat(y,x),16);
		map.addPopup(new OpenLayers.Popup.FramedCloud(
			"chicken",
			new OpenLayers.LonLat(y,x),
			null,
			document.getElementById("searchp").value,
			null,
			true
		));
	}
 }
};
req.send(null);
}
